using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Microsoft.ApplicationBlocks.Data;
using Framework.Library;
using Framework.Library.Utilities;
using Framework.Module.FAQ.Library.Questions;

namespace Framework.Module.FAQ.Library.Providers
{
	public class SqlDataProvider : DataAccessProvider
	{
		private string connectionString = string.Empty;
		public string ConnectionString
		{
			get { return this.connectionString; }
			set { this.connectionString = value; }
		}
		public SqlDataProvider(string strConn)
		{
			this.ConnectionString = strConn;
		}
		public override DataTable GetQuestions()
		{
			DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "FAQ_Questions_GetAvailables", AppEnv.GetLanguage());
			if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
			return null;
		}
        public override DataTable GetQuestionsByFAQ_Show()
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "FAQ_Questions_GetQuestionsByFAQ_Show", AppEnv.GetLanguage());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable getQuestionByFAQShow(int zoneID, string Lang)
        { 
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString,"FAQ_Question_getQuestionByFAQ_Show",zoneID, Lang);
            
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable getZone(int FAQ_Parentid, string lang)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "FAQ_Question_Zone", FAQ_Parentid, lang);
            if(ds!=null && ds.Tables.Count>0) return ds.Tables[0];
            return null;
        }
		public override DataTable GetAllQuestions()
		{
			DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "FAQ_Questions_GetAll", AppEnv.GetLanguage());
			if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
			return null;
		}

        public override DataTable getAll()
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "getAll", AppEnv.GetLanguage());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override DataTable getQuestionWithZone(int zoneid)
        {            
                DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "getQuestion_WithZone", zoneid, AppEnv.GetLanguage());
                if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
                return null;
        }
		public override void SetQuestionIndex(int id, int index)
		{
			SqlHelper.ExecuteDataset(this.ConnectionString, "FAQ_Questions_SetIndex", id, index);
		}

		public override void SetQuestionStatus(int id, bool status)
		{
			SqlHelper.ExecuteDataset(this.ConnectionString, "FAQ_Questions_SetStatus", id, status);
		}
        public override void SetQuestionShow(int id,bool  show)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "FAQ_Questions_SetShow", id, show );
        }

		public override void DeleteQuestion(int _fAQ_ID)
		{
			SqlHelper.ExecuteDataset(this.ConnectionString, "FAQ_Questions_Delete", _fAQ_ID);
		}

		public override int CreateQuestion(QuestionInfo _questionInfo)
		{
            return (int)SqlHelper.ExecuteScalar(this.ConnectionString, "FAQ_Question_Insert", _questionInfo.Name, _questionInfo.Address, _questionInfo.Tel, _questionInfo.Title, _questionInfo.ContentQuestion, _questionInfo.CMS_zoneid, _questionInfo.FAQ_Answer,_questionInfo.FAQ_index, _questionInfo.FAQ_Lang);
		}
        

		public override void UpdateQuestion(QuestionInfo _questionInfo)
		{
			SqlHelper.ExecuteDataset(this.ConnectionString, "FAQ_Questions_Update", _questionInfo.idQ, _questionInfo.ContentQuestion, _questionInfo.FAQ_Answer, _questionInfo.FAQ_Status);
		}
        /// <summary>
        /// create by: Ngoc.N.T Them
        /// date: 03/03/08
        /// </summary>
        /// <param name="_questionInfo"></param>
        public override void UpdateQuestion_Show(QuestionInfo _questionInfo)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "FAQ_Questions_UpdateShow", _questionInfo.idQ, _questionInfo.CMS_zoneid, _questionInfo.Title, _questionInfo.ContentQuestion, _questionInfo.FAQ_Answer, _questionInfo.FAQ_Status, _questionInfo.FAQ_Show );
        }

		public override QuestionInfo GetQuestion(int _fAQ_ID)
		{
			IDataReader dr = SqlHelper.ExecuteReader(this.ConnectionString, "FAQ_Questions_GetInfo", _fAQ_ID);
			QuestionInfo question = (QuestionInfo)ObjectHelper.CreateObject(typeof (QuestionInfo), dr);
			return question;
		}
        public override DataTable get_AllQuestion(int zoneid, string lang)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "FAQ_Questions_GetAll", zoneid, lang);
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
	}
}
